#include "game.h"
#define NOB_IMPLEMENTATION
#define NOB_STRIP_PREFIX
#include "nob.h"
#define OLIVEC_IMPLEMENTATION
#include "olive.c"
#include <stdint.h>
#include <stddef.h>

#define FPS 60
#define DISPLAY_WIDTH 800
#define DISPLAY_HEIGHT 600
static Color display[DISPLAY_WIDTH * DISPLAY_HEIGHT];

#define AUDIO_SAMPLE_RATE 44100
static_assert(AUDIO_SAMPLE_RATE % FPS == 0, "Sample rate must be divisible by FPS");
#define AUDIO_CHANNELS 2
#define AUDIO_CAPACITY (AUDIO_SAMPLE_RATE / FPS * AUDIO_CHANNELS)
static int16_t audio[AUDIO_CAPACITY];

Game game_init(void)
{
    for (size_t i = 0; i < ARRAY_LEN(display); ++i) {
        display[i] = (Color) {
            .r = 18,
            .g = 18,
            .b = 18,
            .a = 255,
        };
    }

    Olivec_Canvas oc = {
        .pixels = (uint32_t*)display,
        .width = DISPLAY_WIDTH,
        .height = DISPLAY_HEIGHT,
        .stride = DISPLAY_WIDTH,
    };

    int cx = DISPLAY_WIDTH / 2;
    int cy = DISPLAY_HEIGHT / 2;
    olivec_triangle3c(oc,
        cx - DISPLAY_WIDTH / 4,
        cy + DISPLAY_HEIGHT / 4,
        cx + DISPLAY_WIDTH / 4,
        cy + DISPLAY_HEIGHT / 4,
        cx,
        cy - DISPLAY_HEIGHT / 4,
        0xFFFF0000,
        0xFF00FF00,
        0xFF0000FF
    );

    return (Game){
        .fps = FPS,
        .display =(uint32_t*) display,
        .display_width = DISPLAY_WIDTH,
        .display_height = DISPLAY_HEIGHT,
        .audio = audio,
        .audio_sample_rate = AUDIO_SAMPLE_RATE,
        .audio_channels = AUDIO_CHANNELS,
    };
}

void game_update(float dt)
{
    
}

void game_key_up(int key)
{
}

void game_key_down(int key)
{
}
